﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Xpo;
using DevExpress.XtraEditors;
using NetworkSupervisor.Model.NetworkSupervisor;
using System.Linq;

namespace NetworkSupervisor
{
    public partial class FormChangePassword : DevExpress.XtraEditors.XtraForm
    {
        public FormChangePassword()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            string user = txtUser.Text;
            string password = txtPassword.Text;
            string newpassword = txtNewPassword.Text;
            if (password == "")
            {
                XtraMessageBox.Show("原始密码不能为空");return;}
            if (newpassword == "")
            {
                XtraMessageBox.Show("新密码不能为空");
                return;
            }

            XPCollection<ta用户> collection = new XPCollection<ta用户>(session1);
            ta用户 item = collection.FirstOrDefault(o => o.用户名 == user && o.密码 == password);
            if (item != null)
            {
                item.密码 = newpassword;
                item.Save();
                XtraMessageBox.Show("密码修改成功");
                DialogResult = DialogResult.OK;
            }
            else
            {
                XtraMessageBox.Show("原始密码错误");
            }
        }

        private void FormLogin_Shown(object sender, EventArgs e)
        {
            txtPassword.Focus();
        }

        private void FormLogin_Load(object sender, EventArgs e)
        {
            Icon = Properties.Resources.app;
        }
    }
}